﻿//************************************************************************************************************
// CoNatural.Data.VisualStudio.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.TemplateWizard;

namespace CoNatural.Data.VisualStudio.TemplateWizard {
	public class CommandWizard : IWizard {
		private EnvDTE.ProjectItem sqlFile;
		private EnvDTE.ProjectItem csFile;

		#region IWizard Members

		public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) {}
		public void ProjectFinishedGenerating(EnvDTE.Project project) {}

		public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) {
			if (projectItem.Name.EndsWith(".sql"))
				sqlFile = projectItem;
			else
				csFile = projectItem;
		}

		public void RunFinished() {
			if (csFile != null && sqlFile != null) {
				string filename = csFile.get_FileNames(0);
				sqlFile.ProjectItems.AddFromFile(filename);
				sqlFile.Properties.Item("BuildAction").Value = "3"; // Embedded Resource
			}

			//StringBuilder sb = new StringBuilder();
			//foreach(EnvDTE.Property p in parentProjectItem.Properties)
			//   sb.Append(p.Name).Append(" = ").AppendLine(p.Value.ToString());
			//System.Windows.Forms.MessageBox.Show(sb.ToString());

			//StringBuilder sb = new StringBuilder();
			//sb.Append("csFile: ").AppendLine(csFile == null ? string.Empty : csFile.get_FileNames(0));
			//sb.Append("sqlFile: ").AppendLine(sqlFile == null ? string.Empty : sqlFile.get_FileNames(0));
			//MessageBox.Show(sb.ToString());
		}

		public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, Microsoft.VisualStudio.TemplateWizard.WizardRunKind runKind, object[] customParams) {}

		public bool ShouldAddProjectItem(string filePath) {
			return true;
		}

		#endregion
	}
}
